import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

// const enums = Store.state.enums

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: {title: '首页', icon: 'dashboard'}
      },
      {
        path: '/changepwd',
        component: () => import('@/views/login/changepwd'),
        hidden: true
      }
    ]
  },

  {
    path: '/student',
    component: Layout,
    redirect: '/student/table',
    name: 'Student',
    meta: {title: '学生', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'list',
        name: 'StudentList',
        component: () => import('@/views/student/list'),
        meta: {title: '学生管理', icon: 'edu-student'}
      }
    ],
  },

  {
    path: '/dept',
    component: Layout,
    redirect: '/dept/table',
    name: 'Dept',
    meta: {
      title: '院系', icon: 'el-icon-s-help',
      roles: ['admin']
    },
    children: [
      {
        path: 'list',
        name: 'DeptList',
        component: () => import('@/views/dept/list'),
        meta: {title: '院系管理', icon: 'edu-dept'}
      }
    ]
  },

  {
    path: '/class',
    component: Layout,
    redirect: '/class/table',
    name: 'Class',
    meta: {title: '班级', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'list',
        name: 'ClassList',
        component: () => import('@/views/class/list'),
        meta: {title: '班级管理', icon: 'edu-class'}
      }
    ]
  },

  {
    path: '/major',
    component: Layout,
    redirect: '/major/table',
    name: 'Major',
    meta: {title: '专业', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'list',
        name: 'MajorList',
        component: () => import('@/views/major/list'),
        meta: {title: '专业管理', icon: 'edu-major'}
      }
    ]
  },

  {
    path: '/teacher',
    component: Layout,
    redirect: '/teacher/table',
    name: 'Teacher',
    meta: {title: '教师', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'list',
        name: 'TeacherList',
        component: () => import('@/views/teacher/list'),
        meta: {title: '教师管理', icon: 'edu-teacher'}
      }
    ]
  },

  {
    path: '/build',
    component: Layout,
    redirect: '/build/table',
    name: 'Build',
    meta: {title: '楼栋', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'list',
        name: 'BuildList',
        component: () => import('@/views/build/list'),
        meta: {title: '楼栋管理', icon: 'edu-build'}
      }
    ]
  },

  {
    path: '/course',
    component: Layout,
    redirect: '/course/table',
    name: 'Course',
    meta: {title: '课程', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'list',
        name: 'CourseList',
        component: () => import('@/views/course/list'),
        meta: {title: '课程管理', icon: 'edu-course'}
      }
    ]
  },

  {
    path: '/config',
    component: Layout,
    redirect: '/config/table',
    name: 'Config',
    meta: {title: '配置', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'list',
        name: 'ConfigList',
        component: () => import('@/views/config/list'),
        meta: {title: '配置管理', icon: 'el-icon-setting'}
      }
    ]
  },

  {
    path: '/admin',
    component: Layout,
    redirect: '/admin/table',
    name: 'Admin',
    meta: {title: '管理员', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'list',
        name: 'AdminList',
        component: () => import('@/views/admin/list'),
        meta: {title: '管理员管理', icon: 'edu-admin'}
      }
    ]
  },

  {
    path: '/classroom',
    component: Layout,
    redirect: '/classroom/table',
    name: 'Classroom',
    meta: {title: '教室', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'list',
        name: 'ClassroomList',
        component: () => import('@/views/classroom/list'),
        meta: {title: '教室管理', icon: 'edu-classroom'}
      }
    ]
  },

  {
    path: '/section',
    component: Layout,
    redirect: '/section/table',
    name: 'Section',
    meta: {title: '节次', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'list',
        name: 'SectionList',
        component: () => import('@/views/section/list'),
        meta: {title: '节次管理', icon: 'edu-section'}
      }
    ]
  },

  {
    path: '/selection',
    component: Layout,
    redirect: '/selection/table',
    name: 'Selection',
    meta: {title: '选课', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'select',
        name: 'SelectionCourse',
        component: () => import('@/views/selection/select'),
        meta: {title: '选课', icon: 'edu-section'}
      },
      {
        path: 'list',
        name: 'SelectionList',
        component: () => import('@/views/selection/list'),
        meta: {title: '选课结果/查询成绩', icon: 'edu-section'}
      }
    ]
  },

  {
    path: '/schedule',
    component: Layout,
    redirect: '/schedule/table',
    name: 'Schedule',
    meta: {title: '排课', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'list',
        name: 'ScheduleCourse',
        component: () => import('@/views/schedule/list'),
        meta: {title: '排课管理', icon: 'edu-selection'}
      },
      {
        path: 'arrange',
        name: 'ScheduleCourse',
        component: () => import('@/views/schedule/arrange'),
        meta: {title: '排课', icon: 'edu-selection'}
      },
      {
        path: 'record',
        name: 'ArrangeRecord',
        component: () => import('@/views/schedule/record'),
        meta: {title: '排课记录', icon: 'edu-selection'},
      }
    ]
  },

  {
    path: '/apply',
    component: Layout,
    redirect: '/apply/table',
    name: 'Apply',
    meta: {title: '调课申请', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'list',
        name: 'ApplyList',
        component: () => import('@/views/apply/list'),
        meta: {title: '调课申请', icon: 'edu-selection'}
      }
    ]
  },

  // 404 page must be placed at the end !!!
  {path: '*', redirect: '/404', hidden: true}
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
